﻿<?php
class LoginAction extends Action{
	public function login(){
		$this->display();
	}
	public function dologin(){
		$username=$_POST['username'];
		$password=$_POST['password'];
		$code=$_POST['code'];
		
		if(md5($code)!=$_SESSION['code']){
			$this->error('验证码错误');
		}
		$data['username']=$username;
		$data['password']=$password;
		$m=M('youth');
		$youth=$m->select();
		//dump($youth);
		$count=$m->where($data)->find();
		if($count>0){
			$_SESSION['username']=$username;
			$_SESSION['id']=$youth['id'];
			
			$this->success('登录成功',U('Index/index'));	
		}else{
			$this->error('用户名不存在');
		}	
	}
	public function logout(){
		$_SESSION=array();
	if(isset($COOKIE[session_name()])){
		setcookie(session_name(),'',time()-1,'/');
	}
		session_destroy();
		$this->redirect('Index/index');
	}
}
?>